package com.selfdriving.activity;

import java.util.ArrayList;
import java.util.List;
import net.tsz.afinal.annotation.view.ViewInject;
import com.selfdriving.R;
import com.selfdriving.adapter.CommentAdapter;
import com.selfdriving.bean.Comment;
import com.selfdriving.utils.DeviceUtils;
import com.selfdriving.utils.LogUtil;

import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.ListView;
import android.widget.RadioButton;

public class FeatureCommentActivity extends BaseActivity implements
		OnCheckedChangeListener {
	@ViewInject(id = R.id.comment_list)
	ListView comment_list;

	@ViewInject(id = R.id.include_filter_area)
	View area;

	@ViewInject(id = R.id.include_filter_sort)
	View sort;

	@ViewInject(id = R.id.btnArea,click="btnArea")
	CheckBox btnArea;

	@ViewInject(id = R.id.btnSort,click="btnSort")
	CheckBox btnSort;

	private CommentAdapter adapter;

	private List<Comment> comments;

	private boolean isAreaShow = false;

	private boolean isSortShow = false;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.feature_comment);
		comments = new ArrayList<Comment>();
		for (int i = 0; i < 6; i++) {
			Comment comment = new Comment();
			comments.add(comment);
		}
		adapter = new CommentAdapter(this, comments);
		comment_list.setAdapter(adapter);
		DeviceUtils.setListViewHeightBasedOnChildren(comment_list);
		comment_list.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
					long arg3) {
				
			}
		});
	}

	public void btnArea(View v) {
		sort.setVisibility(View.GONE);
		isAreaShow = !isAreaShow;
		isSortShow=false;
		btnSort.setChecked(false);
		if (isAreaShow) {
			area.setVisibility(View.VISIBLE);
			btnArea.setChecked(true);
		} else {
			area.setVisibility(View.GONE);
			btnSort.setChecked(false);
		}
	}

	public void btnSort(View v) {
		area.setVisibility(View.GONE);
		isSortShow = !isSortShow;
		btnArea.setChecked(false);
		isAreaShow=false;
		if (isSortShow) {
			sort.setVisibility(View.VISIBLE);
			btnSort.setChecked(true);
		} else {
			sort.setVisibility(View.GONE);
			btnArea.setChecked(false);
		}
	}

	@Override
	public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
		if (isChecked) {
			switch (buttonView.getId()) {
			case R.id.btnArea:
				isAreaShow = !isAreaShow;
				LogUtil.e("isAreaShow:" + isAreaShow);
				if (isChecked) {
					area.setVisibility(View.VISIBLE);
					sort.setVisibility(View.GONE);
				} else {
					area.setVisibility(View.GONE);
				}
				break;
			case R.id.btnSort:
				isSortShow = !isSortShow;
				LogUtil.e("isSortShow:" + isSortShow);
				if (isChecked) {
					sort.setVisibility(View.VISIBLE);
					area.setVisibility(View.GONE);
				} else {
					sort.setVisibility(View.GONE);
				}
				break;
			default:
				break;
			}
		}
	}
}
